package com.youku.component.report;

import com.youku.component.TestCase;
import com.youku.util.TimeHelper;

/**
 * 测试记录
 * 
 * @author loda
 *
 */
public class TestRecord {

	/**
	 * 测试用例
	 */
	private TestCase testCase;

	/**
	 * 是否通过测试
	 */
	private RecordStatus status;

	/**
	 * 如果未通过测试，那么出现的提示信息
	 */
	private String message;

	/**
	 * 测试用例执行时间
	 */
	private String createtime;

	private TestRecord(TestCase testCase, RecordStatus status, String message) {
		super();
		this.testCase = testCase;
		this.status = status;
		this.message = message;
		this.createtime = TimeHelper.formatNow("yyyy-MM-dd HH:mm:ss");
	}

	public static final TestRecord createSuccessRecord(TestCase testCase) {
		return new TestRecord(testCase, RecordStatus.SUCCESS, "");
	}

	public static final TestRecord createFailRecord(TestCase testCase, String message) {
		return new TestRecord(testCase, RecordStatus.FAIL, message);
	}

	public String getCaseId() {
		return testCase.getId();
	}

	public String getSuiteId() {
		return testCase.getSuiteId();
	}

	public String getProjectId() {
		return testCase.getProjectId();
	}

	public RecordStatus getStatus() {
		return status;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public void setStatus(RecordStatus status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public TestCase getTestCase() {
		return testCase;
	}

	public void setTestCase(TestCase testCase) {
		this.testCase = testCase;
	}

	public String statusForCn() {
		if (status == RecordStatus.SUCCESS)
			return "成功";
		else
			return "失败";
	}

	public String statusForEn() {
		if (status == RecordStatus.SUCCESS)
			return "success";
		else
			return "failure";
	}

	public static enum RecordStatus {
		SUCCESS("通过", "green"), FAIL("未通过", "red");

		private String message;

		private String color;

		private RecordStatus(String message, String color) {
			this.message = message;
			this.color = color;
		}

		public String message() {
			return message;
		}

		public String color() {
			return color;
		}
	}
}
